<?php

use yii\helpers\Html;
use yii\helpers\Url;
use kartik\grid\GridView;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var backend\models\search\ProductSearch $searchModel
 */

$this->title                   = Yii::t('models', 'Products');
$this->params['breadcrumbs'][] = $this->title;

$columus = [
    [
        'class'              => 'kartik\grid\SerialColumn',
        'contentOptions'     => ['class' => 'kartik-sheet-style'],
        'width'              => '36px',
        'pageSummary'        => 'Total',
        'pageSummaryOptions' => ['colspan' => 6],
        'header'             => '',
        'headerOptions'      => ['class' => 'kartik-sheet-style']
    ],

    [
        'class'         => 'kartik\grid\CheckboxColumn',
        'width'         => '36px',
        'headerOptions' => ['class' => 'kartik-sheet-style'],
    ],
    [
        'class'          => 'yii\grid\ActionColumn',
        'template'       => "{view} &nbsp; {update} &nbsp; {delete}",
        'buttons'        => [
            'view' => function ($url, $model, $key) {
                $options = [
                    'title'      => Yii::t('cruds', 'View'),
                    'aria-label' => Yii::t('cruds', 'View'),
                    'data-pjax'  => '0',
                ];
                return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
            }
        ],
        'urlCreator'     => function ($action, $model, $key, $index) {
            // using the column name as key, not mapping to 'id' like the standard generator
            $params    = is_array($key) ? $key : [$model->primaryKey()[0] => (string)$key];
            $params[0] = Yii::$app->controller->id ? Yii::$app->controller->id . '/' . $action : $action;
            return Url::toRoute($params);
        },
        'contentOptions' => ['nowrap' => 'nowrap']
    ],


    [
        'class'         => 'kartik\grid\ExpandRowColumn',
        'width'         => '50px',
        'value'         => function ($model, $key, $index, $column) {
            return GridView::ROW_COLLAPSED;
        },
        // uncomment below and comment detail if you need to render via ajax
        // 'detailUrl' => Url::to(['/site/book-details']),
        'detail'        => function ($model, $key, $index, $column) {
            return 'dddd';//Yii::$app->controller->renderPartial('_expand-row-details', ['model' => $model]);
        },
        'headerOptions' => ['class' => 'kartik-sheet-style'],
        'expandOneOnly' => true
    ],

    [
        'attribute'           => 'name',
        'width'               => '80px',
        'filterType'          => GridView::FILTER_SELECT2,
        'filter'              => ['333'],
        'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true], 'hideSearch' => false,],
        'filterInputOptions'  => ['placeholder' => Yii::t('app', 'please_select')],
        'format'              => 'raw',
        'visible'             => true,
    ],
    [
        'attribute' => 'slug',
        'width'     => '90px',
    ],
    'content',
    'x',
    'y',
    [
        'attribute' => 'address',
        'visible'   => false,
    ],
    [
        'attribute'           => 'created_at',
        'filterType'          => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]],
        'format'              => 'raw',
        'visible'             => false,
    ],
    [
        'attribute'           => 'updated_at',
        'filterType'          => GridView::FILTER_DATE_RANGE,
        'filterWidgetOptions' => ['pluginOptions' => ['allowClear' => true]],
        'format'              => 'raw',
        'visible'             => false,
    ],
    'created_by',
    'updated_by',
];


echo \backend\widgets\GridWidget::widget(
    [
        'dataProvider' => $dataProvider,
        'gridColumns'  => $columus,
        'searchModel'  => $searchModel
    ]
);

?>


